/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package model.dao.bacsi;

import java.util.Date;
import java.util.List;
import model.dao.AbstractQuery;
import model.dao.ProjectQuery;
import model.dao.admin.AdminDAO;
import model.entity.BacSi;
import model.entity.Gia;
import model.util.HibernateUtil;
import org.hibernate.HibernateException;
import org.hibernate.Session;

/**
 *
 * @author Admin
 */
public class BacSiDAO {
     private static final String LOAD_1_BACSI = "FROM BacSi bs WHERE bs.bsMa =";
     
     /**
     * Thêm mới một bác sĩ
     *
     * @param bs đối tượng bác sĩ cần thêm
     */
//    public static  void insertBacSi(BacSi bs){
////        AbstractQuery.insertObject(bs.getAdmin());
//        AbstractQuery.insertObject(bs);
//    }
     
     public static final int insertBacSi(BacSi bs){
         Session session = HibernateUtil.getSessionFactory().openSession();
         int id;
         try {
             AdminDAO.insertAdmin(bs.getAdmin());
             session.beginTransaction();
             session.save(bs);
             session.getTransaction().commit();
             id = bs.getBsMa();
         } catch (HibernateException e) {
             session.getTransaction().rollback();
             throw  new HibernateException(e);
         }finally{
             session.close();
         }
         return id;
     }
    
    public static void updateBacSi(BacSi bs){
        AbstractQuery.updateObject(bs);
    }
    public static  void deleteBacSi(int bsMa){
        AbstractQuery.modifyObject(3, AbstractQuery.loadObject(LOAD_1_BACSI + bsMa).get(0));
    }
    /**
     * liệt kê theo tên bác sĩ
     */
    public static final List<BacSi> lietKeTheoTenBacSi(String bsTen){
        List list = AbstractQuery.loadObject(ProjectQuery.LOAD_2_BACSI  +"'"+ bsTen+"'");
         return list;
    }
    /**
     * tìm kiếm theo mã bác sĩ để load xuống database
     */
    public static final List<BacSi> timKiemTheoMaBacSi(int bsMa){
        List list = AbstractQuery.loadObject(ProjectQuery.LOAD_1_BACSI + bsMa);
        return list;
        
    }

   
}
